#ifndef _DSWCONSOLE_GPRS_H
#define _DSWCONSOLE_GPRS_H

#include "dswconsole_base.h"
#include "dswconsole_gprs_axsession.h"
#include "dswconsole_gprs_msgsession.h"

typedef bool (CB_GPRSCOM_FUNC)(const char* pCmd, char* pData, int nLen, void* pCaller);
typedef struct{
	const char* scmd;
	CB_GPRSCOM_FUNC* pFunc;
} ST_GPRS_FUNC;

#define SMS_READY 0x0001
#define PHB_READY 0x0002
#define AT_READY 0x0080
#define USIM_READY 0x0100
#define GSM_READY 0x0200
#define GPRS_READY 0x0400
#define SIM_READY 0x0800

class CDswconsole_gprs : public CDswconsole_base
{
public:
	CDswconsole_gprs(LPST_ENV_T pEnv, EN_CON_SESSION_TYPE nType, LPST_CONSOLE_INFO_T pInfo);
	virtual ~CDswconsole_gprs();
public:
	static CDswconsole_gprs* createNew(LPST_ENV_T pEnv);
	void SetCaptureResult(LPST_CAPTURE_RESULT_T pResult);
	bool IsLinkServer();
private:
	virtual bool SeekToStartComm(LPST_COMM_RECV_T pCommRecv, int &nPayloadSize);
	bool ProcessData_Ex(char* pData, int nLen);
private:
	void SendData(char* pData, int nLen){usleep(1000 * 50);evbuffer_add(bufferevent_get_output(m_pBev), pData, nLen);};
	
	static void cbCheckSIMFunc(int fd, short events, void* ctx){((CDswconsole_gprs*)ctx)->CheckSIMFunc(fd, events);};
	void CheckSIMFunc(int fd, short events);
	static void cbCheckCSQFunc(int fd, short events, void* ctx){((CDswconsole_gprs*)ctx)->CheckCSQFunc(fd, events);};
	void CheckCSQFunc(int fd, short events);
	static void cbCheckCREGFunc(int fd, short events, void* ctx){((CDswconsole_gprs*)ctx)->CheckCREGFunc(fd, events);};
	void CheckCREGFunc(int fd, short events);
	static void cbHeartBeetFunc(int fd, short events, void* ctx){((CDswconsole_gprs*)ctx)->HeartBeetFunc(fd, events);};
	void HeartBeetFunc(int fd, short events);
	static void cbAlarmCheckFunc(int fd, short events, void* ctx){((CDswconsole_gprs*)ctx)->AlarmCheckFunc(fd, events);};
	void AlarmCheckFunc(int fd, short events);
	static void cbCreateMsgSessionFunc(int fd, short events, void* ctx){((CDswconsole_gprs*)ctx)->CreateMsgSessionFunc(fd, events);};
	void CreateMsgSessionFunc(int fd, short events);

	static void cbCheckGPRSTimeOutFunc(int fd, short events, void* ctx){((CDswconsole_gprs*)ctx)->CheckGPRSTimeOutFunc(fd, events);};
	void CheckGPRSTimeOutFunc(int fd, short events);

	static void cbGPRSModulePowerOnFunc(int fd, short events, void* ctx){((CDswconsole_gprs*)ctx)->GPRSModulePowerOnFunc(fd, events);};
	void GPRSModulePowerOnFunc(int fd, short events);
public:
	static void cbOnMissionNotify(LPST_MISSION_NOTIFY_T nNotify, void* pCaller){((CDswconsole_gprs*)pCaller)->OnMissionNotify(nNotify);};
	void OnMissionNotify(LPST_MISSION_NOTIFY_T pNotify);

	static bool cbOnBooting_EIND(const char* pCmd, char* pData, int nLen, void* pCaller){return ((CDswconsole_gprs*)pCaller)->OnBooting_EIND(pCmd, pData, nLen);};
	bool OnBooting_EIND(const char* pCmd, char* pData, int nLen);
	static bool cbOnBooting_EUSIM(const char* pCmd, char* pData, int nLen, void* pCaller){return ((CDswconsole_gprs*)pCaller)->OnBooting_EUSIM(pCmd, pData, nLen);};
	bool OnBooting_EUSIM(const char* pCmd, char* pData, int nLen);
	static bool cbOnCCID(const char* pCmd, char* pData, int nLen, void* pCaller){return ((CDswconsole_gprs*)pCaller)->OnCCID(pCmd, pData, nLen);};
	bool OnCCID(const char* pCmd, char* pData, int nLen);
	static bool cbOnCSQ(const char* pCmd, char* pData, int nLen, void* pCaller){return ((CDswconsole_gprs*)pCaller)->OnCSQ(pCmd, pData, nLen);};
	bool OnCSQ(const char* pCmd, char* pData, int nLen);
	static bool cbOnCREG(const char* pCmd, char* pData, int nLen, void* pCaller){return ((CDswconsole_gprs*)pCaller)->OnCREG(pCmd, pData, nLen);};
	bool OnCREG(const char* pCmd, char* pData, int nLen);
	static bool cbOnMIPCALL(const char* pCmd, char* pData, int nLen, void* pCaller){return ((CDswconsole_gprs*)pCaller)->OnMIPCALL(pCmd, pData, nLen);};
	bool OnMIPCALL(const char* pCmd, char* pData, int nLen);
	static bool cbOnGPRSConnected(const char* pCmd, char* pData, int nLen, void* pCaller){return ((CDswconsole_gprs*)pCaller)->OnGPRSConnected(pCmd, pData, nLen);};
	bool OnGPRSConnected(const char* pCmd, char* pData, int nLen);
	static bool cbOnGPRSWatingData(const char* pCmd, char* pData, int nLen, void* pCaller){return ((CDswconsole_gprs*)pCaller)->OnGPRSWatingData(pCmd, pData, nLen);};
	bool OnGPRSWatingData(const char* pCmd, char* pData, int nLen);
	static bool cbOnGPRSSendedData(const char* pCmd, char* pData, int nLen, void* pCaller){return ((CDswconsole_gprs*)pCaller)->OnGPRSSendedData(pCmd, pData, nLen);};
	bool OnGPRSSendedData(const char* pCmd, char* pData, int nLen);
	static bool cbOnGPRSPushedData(const char* pCmd, char* pData, int nLen, void* pCaller){return ((CDswconsole_gprs*)pCaller)->OnGPRSPushedData(pCmd, pData, nLen);};
	bool OnGPRSPushedData(const char* pCmd, char* pData, int nLen);
	static bool cbOnGPRSDisconnect(const char* pCmd, char* pData, int nLen, void* pCaller){return ((CDswconsole_gprs*)pCaller)->OnGPRSDisconnect(pCmd, pData, nLen);};
	bool OnGPRSDisconnect(const char* pCmd, char* pData, int nLen);
	static bool cbOnGPRSSocketClose(const char* pCmd, char* pData, int nLen, void* pCaller){return ((CDswconsole_gprs*)pCaller)->OnGPRSSocketClose(pCmd, pData, nLen);};
	bool OnGPRSSocketClose(const char* pCmd, char* pData, int nLen);
	static bool cbOnGPRSError(const char* pCmd, char* pData, int nLen, void* pCaller){return ((CDswconsole_gprs*)pCaller)->OnGPRSError(pCmd, pData, nLen);};
	bool OnGPRSError(const char* pCmd, char* pData, int nLen);
	static bool cbOnGPRSRing(const char* pCmd, char* pData, int nLen, void* pCaller){printf("ring................\n");return true;};
private:
	timer_param_t m_nCheckSIMTask, m_nCheckCSQTask, m_nCheckCREGTask, m_nHeartBeetTask, m_nAlarmCheckTask;
	int m_nModuleState, m_nRegistCount;
	time_t m_nRegistLastAnsyTime;

	t_svr_param m_regSvrParam, m_alarmSvrParam, m_msgSvrParam;

	CDswconsole_gprs_axsession *m_pCenterSession, *m_pRegisterSession, *m_pAlarmSession;
	CDswconsole_gprs_msgsession *m_pMsgSession;

	ST_LIST_CAPTURE_RESULT_T m_result_list;

	bool m_bAlarmSvrConnecting;

	timer_param_t m_nCreateMsgSessionTask, m_nCheckGprsTimeoutTask, m_nGprsModulePowerOnTask;
};

#endif

